﻿using HR.Config;
using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;

namespace HR.Controllers
{
    public class JobRegistController : Controller
    {
        private readonly IJobRegistService ijs;
        /// <summary>
        /// 三个机构的
        /// </summary>
        private readonly IFirst_kindService fkService;
        private readonly ISecond_kindService skService;
        private readonly IThird_kindService tsService;
        /// <summary>
        /// 职位类型分类
        /// </summary>
        private readonly IConfig_majorKindService icmks;
        /// <summary>
        /// 职位称呼
        /// </summary>
        private readonly IJob_setService jss;

        public JobRegistController(IJobRegistService ijs, IFirst_kindService fkService, ISecond_kindService skService, IThird_kindService tsService, IConfig_majorKindService icmks, IJob_setService jss)
        {
            this.ijs = ijs;
            this.fkService = fkService;
            this.skService = skService;
            this.tsService = tsService;
            this.icmks = icmks;
            this.jss = jss;
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 职位发布登记
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 职位发布登记
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> EngageMajorReleaseAdd([FromBody] engage_major_release emr)
        {
            emr.register = HttpContext.Session.GetString("uname");
            int res = await ijs.EngageMajorReleaseAdd(emr);
            return Json(res);
        }
        /// <summary>
        /// 查询已经发布的所有职位信息
        /// </summary>
        /// <param name="pgsize"></param>
        /// <param name="pgcurrent"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> EngageMajorReleaseFill(int pgsize, int pgcurrent)
        {
            Paging<engage_major_release> pg = await ijs.EngageMajorReleaseFill(pgsize, pgcurrent);
            return Json(pg);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 职位发布更改视图跳转
        /// </summary>
        /// <returns></returns>
        public IActionResult IndexUdp()
        {
            return View();
        }
        /// <summary>
        /// 点击编辑按钮后下拉列表框数据源
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> FindComboxs()
        {
            Paging<config_file_first_kind> p1 = await fkService.FirstKindPage();
            Paging<config_file_second_kind> p2 = await skService.SecondKindPage();
            Paging<config_file_third_kind> p3 = await tsService.ThirdKindPage();
            List<config_major_kind> p4 = await icmks.CMKOnPageFill();
            Paging<config_public_char> p5 = await jss.JobSetFill();
            var list = new List<object>();
            list.Add(p1);
            list.Add(p2);
            list.Add(p3);
            list.Add(p4);
            list.Add(p5);
            return Json(list);
        }
        /// <summary>
        /// 职位登记确认修改操作
        /// </summary>
        /// <param name="emr"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> EngageMajorReleaseUpdate([FromBody] engage_major_release emr)
        {
            emr.changer = HttpContext.Session.GetString("uname");
            int res = await ijs.EngageMajorReleaseUpdate(emr);
            return Json(res);
        }
        /// <summary>
        /// 职位登记确认删除操作
        /// </summary>
        /// <param name="mre_id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> EngageMajorReleaseDelete(short mre_id)
        {
            int res = await ijs.EngageMajorReleaseDelete(mre_id);
            return Json(res);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        /// <summary>
        /// 职位发布查询视图跳转
        /// </summary>
        /// <returns></returns>
        public IActionResult IndexFind()
        {
            return View();
        }

    }
}
